package cn.bugstack.springframework.core.io;

import cn.hutool.core.lang.Assert;

import java.net.MalformedURLException;
import java.net.URL;

/**
 * @author ouyangzhao
 */
public class DefaultResourceLoader implements ResourceLoader{



    @Override
    public Resource getInputStream(String location) {
        Assert.notNull(location, "location cannot be null");
        if (location.startsWith(CLASSPATH_URL_PREFIX)){
            return new ClassPathResource(location.substring(CLASSPATH_URL_PREFIX.length()));
        }else{
            try {
                return new UrlResource(new URL(location));
            }catch ( MalformedURLException e){
                return new FileSystemResource(location);
            }
        }

    }
}
